<template>
  <el-container>
    <el-main>
      <div>
        <el-form :inline="true" :model="book" class="form-inline">
          <el-form-item label="书名">
            <el-input v-model="book.name" placeholder="请输入书名"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchBooks">查询</el-button>
          </el-form-item>
        </el-form>
        <div v-if="bookmanage">
          <booktable :tableData="tableData"></booktable>
        </div>
      </div>
    </el-main>
  </el-container>

</template>
<script>
import axios from "axios";
import booktable from "../components/table/bookusertable.vue";
import tablemanage from "../components/table/tablemanage.vue";
import appbar from "../components/app-bar.vue";
export default {
  name: "borrow",
  props: {
    tableData: {
      type: Array,
    },
  },
  components: {
    appbar: appbar,
    booktable: booktable,
    tablemanage: tablemanage,
  },
  data() {
    return {
      book: {
        name: "",
      },
      activeName: "first",
      bookmanage: true,
      msgmanage: false,
      bookData: [],
      watch: {
        group() {
          this.drawer = false;
        },
      },
    };
  },
  methods: {
    handleClick() {
      if (this.activeName == "first") {
        this.bookmanage = true;
        this.tablemanagestate = false;
        this.msgmanage = false;
      } else if (this.activeName == "second") {
        this.bookmanage = false;
        this.tablemanagestate = true;
        this.msgmanage = false;
      } else {
        this.bookmanage = false;
        this.tablemanagestate = false;
        this.msgmanage = true;
      }
    },
    searchBooks() {
      axios({
        method: "get",
        url:
          this.$root.businessServer +
          "thebookInfo/get_theBookInfo?book_name=" +
          this.book.name,
      })
        .then((response) => {
          this.bookData = [response.data];
          this.tableData=this.bookData;
          this.bookmanage = false;
        })
        //Promise解决props传值局部刷新的问题，等待消息队列异步执行完成后的数据挂载，局部刷新组件的显示
        .then(() => {
          this.bookmanage = true;
        })
        .catch((error) => {});
    },
  },
};
</script>